package com.zz.source.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zz.source.entity.User;
import com.zz.source.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenglei
 * @since 2021-08-15
 */
@RestController
@RequestMapping("/source/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * @Date: 14:42 2021/8/15
     * @Param: []
     * @return: java.util.List<com.zz.source.entity.User>
     * @Description: 查询所有数据
     **/
    @GetMapping("findAll")
    public List<User> findAll() {
        return userService.list();
    }

    /**
     * @Date: 14:54 2021/8/15
     * @Param: [id]
     * @return: com.zz.source.entity.User
     * @Description: 通过id进行查询
     **/
    @GetMapping("findById")
    public User findById(Integer id) {
        return userService.getById(id);
    }

    /**
     * @Date: 14:59 2021/8/15
     * @Param: [name, sex]
     * @return: java.util.List<com.zz.source.entity.User>
     * @Description: 根据姓名和性别查询
     **/
    @GetMapping("findNameAndSex")
    public List<User> findNameAndSex(String name, String sex) {
        return userService.findNameAndSex(name, sex);
    }

    /**
     * @Date: 15:12 2021/8/15
     * @Param: [id, name]
     * @return: int
     * @Description: 根据id修改姓名
     **/
    @GetMapping("updateSetNameAndById")
    public int updateSetNameAndById(Integer id, String name) {
        return userService.updateSetNameAndById(id, name);
    }

    /**
     * @Date: 15:21 2021/8/15
     * @Param: [id, name, username, sex, age]
     * @return: int
     * @Description: 新增用户
     **/
    @GetMapping("insertUser")
    public int insertUser(Integer id, String name, String username, String sex, Integer age) {
        return userService.insertUser(id, name, username, sex, age);

    }

    /**
    * @Date: 15:34 2021/8/15
    * @Param: [id]
    * @return: int
    * @Description: 根据id删除用户
    **/
    @GetMapping("deleteById")
    public int deleteById(Integer id){
        return userService.deleteById(id);
    }

    /**
    * @Date: 15:40 2021/8/15
    * @Param: []
    * @return: java.util.List<com.zz.source.entity.User>
    * @Description: 查询所有用户的名字的性别
    **/
    @GetMapping("findAllNameAndSex")
    public List<User> findAllNameAndSex(){
        return userService.findAllNameAndSex();
    }

    /**
     * @Date: 9:59 2021/8/17
     * @Param: [current, size]
     * @return: com.baomidou.mybatisplus.core.metadata.IPage<com.zz.source.entity.User>
     * @Description: 分页查询
     **/
    @GetMapping("findAllByPage")
    public IPage<User> findAllByPage(Integer current,Integer size){

        return userService.findAllByPage(current,size);
    }


}
